﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Things.Web.Components
{
    public partial class Trade : System.Web.UI.UserControl
    {
        private string tradeCode;
        public string TradeCode
        {
            get
            {
                string temp = null;
                try
                {
                    if (string.IsNullOrEmpty(tradeCode) == true)
                    {
                        if (Request.QueryString["code"] != null)
                        {
                            temp = Request.QueryString["code"].Trim();
                        }
                    }
                    else
                    {
                        temp = tradeCode;
                    }
                }
                catch
                {
                    temp = string.Empty;
                }
                return temp;
            }
            set
            {
                tradeCode = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void BindData()
        {
            
            Things.BLL.Goods gBLL = new BLL.Goods();
            DataSet ds = gBLL.GetTrade(TradeCode);

            /* Farmer */
            DataTable dt1=ds.Tables[0];
            if (dt1.Rows.Count > 0)
            {
                DataRow dr1 = dt1.Rows[0];
                lblFarmer.Text = dr1["FarmerName"] + " " + dr1["Address"] + " " + dr1["TelPhone"] + " " + dr1["MobilePhone"];
            }
            /* Farm */
            DataTable dt2 = ds.Tables[1];
            if (dt2.Rows.Count > 0)
            {
                DataRow dr2 = dt2.Rows[0];
                lblFarm.Text = dr2["Address"].ToString();
            }
            /* Plant progress */
            DataTable dt3 = ds.Tables[2];
            gvPlantProgress.DataSource = dt3;
            gvPlantProgress.DataBind();

            /* Farm */
            DataTable dt4 = ds.Tables[3];
            if (dt4.Rows.Count > 0)
            {
                DataRow dr4 = dt4.Rows[0];
                lblFactory.Text = dr4["FactoryName"].ToString() + " " + dr4["Address"] + "  " + dr4["Phone"];
            }
            /* Plant progress */
            DataTable dt5= ds.Tables[4];
            gvProductProgress.DataSource = dt5;
            gvProductProgress.DataBind();

        }

     
    }
}